/*
 * @Description: 
 * @Author: Yong
 * @Date: 2021-09-22 22:16:54
 * @LastEditTime: 2021-09-28 10:17:07
 */
import { BrowserRouter as Router, Route, Redirect } from 'react-router-dom'
import { lazy, Suspense } from 'react'

import Home from './pages/Home'
import AuthRoute from './components/AuthRoute'
// 懒加载组件
const CityList = lazy(() => import('./pages/CityList'))
const MapPage = lazy(() => import('./pages/Map'))
const HouseDetail = lazy(() => import('./pages/HouseDetail'))
const Login = lazy(() => import('./pages/Login'))
// 房源发布
const Rent = lazy(() => import('./pages/Rent'))
const RentAdd = lazy(() => import('./pages/Rent/Add'))
const RentSearch = lazy(() => import('./pages/Rent/Search'))

export default function App () {
	return (

		<Router>
			<Suspense fallback={<div>loading...</div>}>
				<div className="App">
					{/* 默认/跳转至Home页面 */}
					<Route path="/" exact render={() => <Redirect to="/home" />} />
					<Route path="/home" component={Home} />
					<Route path="/cityList" component={CityList} />
					<Route path="/map" component={MapPage} />
					<Route path="/detail/:id" component={HouseDetail} />
					<Route path="/login" component={Login} />

					{/* 需要登录证后后才能访问的路由 */}
					<AuthRoute exact path="/rent" component={Rent} />
					<AuthRoute path="/rent/add" component={RentAdd} />
					<AuthRoute path="/rent/search" component={RentSearch} />
				</div>
			</Suspense>
		</Router>
	)
}